<include file="Public/min-header"/>
<link href="__PUBLIC__/plugins/daterangepicker/daterangepicker-bs3.css" rel="stylesheet" type="text/css"/>
<script src="__PUBLIC__/plugins/daterangepicker/moment.min.js" type="text/javascript"></script>
<script src="__PUBLIC__/plugins/daterangepicker/daterangepicker.js" type="text/javascript"></script>
<div class="wrapper">
    <include file="Public/breadcrumb"/>
    <section class="content ">
        <!-- Main content -->
        <div class="container-fluid">
            <div class="pull-right">
                <a href="javascript:history.go(-1)" data-toggle="tooltip" title="" class="btn btn-default"
                   data-original-title="返回"><i class="fa fa-reply"></i></a>
            </div>
            <div class="panel panel-default">
                <div class="panel-heading">
                    <h3 class="panel-title"><i class="fa fa-list"></i> 添加优惠券</h3>
                </div>
                <div class="panel-body ">
                    <!--表单数据-->
                    <form action="" id="coupon_form" method="post">
                        <!--通用信息-->
                        <div class="tab-content col-md-10">
                            <div class="tab-pane active" id="tab_tongyong">
                                <table class="table table-bordered">
                                    <tbody>
                                    <tr>
                                        <td class="col-sm-2">优惠券名称：</td>
                                        <td class="col-sm-4">
                                            <input type="text" value="{$coupon.name}" class="form-control" id="name"
                                                   name="name">
                                            <span id="err_attr_name" style="color:#F00; display:none;"></span>
                                        </td>
                                        <td class="col-sm-4">请填写优惠券名称
                                        </td>
                                    </tr>
                                    <tr>
                                        <td>优惠券面额：</td>
                                        <td>
                                            <input type="text" value="{$coupon.money}" class="form-control" id="money"
                                                   name="money" onpaste="this.value=this.value.replace(/[^\d.]/g,'')"
                                                   onkeyup="this.value=this.value.replace(/[^\d.]/g,'')"/>
                                        </td>
                                        <td class="col-sm-4">优惠券可抵扣金额</td>
                                    </tr>
                                    <tr>
                                        <td>消费金额：</td>
                                        <td>
                                            <input type="text" value="{$coupon.condition}" class="form-control active"
                                                   id="condition" name="condition"
                                                   onpaste="this.value=this.value.replace(/[^\d.]/g,'')"
                                                   onkeyup="this.value=this.value.replace(/[^\d.]/g,'')"/>
                                        </td>
                                        <td class="col-sm-4">订单需满足的最低消费金额(必需为整数)才能使用</td>
                                    </tr>
                                    <tr>
                                        <td>发放类型:</td>
                                        <td id="order-status">
                                            <input name="type" type="radio" value="0"
                                            <if condition="$coupon['type'] eq 0">checked</if>
                                            >面额模板
                                            <input name="type" type="radio" value="1"
                                            <if condition="$coupon['type'] eq 1">checked</if>
                                            >按用户发放
                                            <!--
                                            <input name="type" type="radio" value="2" <if condition="$coupon['type'] eq 2">checked</if> >注册发放
                                            <input name="type" type="radio" value="3" <if condition="$coupon['type'] eq 3">checked</if> >邀请发放
                                            -->
                                            <input name="type" type="radio" value="4"
                                            <if condition="$coupon['type'] eq 4">checked</if>
                                            >线下发放
                                        </td>
                                    </tr>
                                    <tr>
                                        <td>发放数量:</td>
                                        <td><input type="text" value="{$coupon.createnum}" class="form-control"
                                                   id="createnum" name="createnum" placeholder="0"
                                                   onpaste="this.value=this.value.replace(/[^\d]/g,'')"
                                                   onkeyup="this.value=this.value.replace(/[^\d]/g,'')"/></td>
                                        <td class="col-sm-4">发放数量限制(默认为0则无限制)</td>
                                    </tr>
                                    <tr class="timed">
                                        <td>发放起始日期:</td>
                                        <td>
                                            <div class="input-prepend input-group">
			                                <span class="add-on input-group-addon">
			                                      <i class="glyphicon glyphicon-calendar fa fa-calendar">  </i>
			                                </span>
                                                <input type="text"
                                                       value="{$coupon.send_start_time|date='Y-m-d H:i:s',###}"
                                                       class="form-control" id="send_start_time" name="send_start_time">
                                            </div>
                                        </td>
                                        <td class="col-sm-4"></td>
                                    </tr>

                                    <tr class="timed">
                                        <td>发放结束日期:</td>
                                        <td>
                                            <div class="input-prepend input-group">
			                                <span class="add-on input-group-addon">
			                                        <i class="glyphicon glyphicon-calendar fa fa-calendar"> </i>
			                                </span>
                                                <input type="text"
                                                       value="{$coupon.send_end_time|date='Y-m-d H:i:s',###}"
                                                       class="form-control" id="send_end_time" name="send_end_time">
                                            </div>
                                        </td>
                                        <td class="col-sm-4"></td>
                                    </tr>
                                    <tr>
                                        <td>使用起始日期:</td>
                                        <td>
                                            <div class="input-prepend input-group">
			                                <span class="add-on input-group-addon">
			                                    <i class="glyphicon glyphicon-calendar fa fa-calendar"></i>
			                                </span>
                                                <input type="text"
                                                       value="{$coupon.use_start_time|date='Y-m-d H:i:s',###}"
                                                       class="form-control" id="use_start_time" name="use_start_time">
                                            </div>
                                        </td>
                                        <td class="col-sm-4"></td>
                                    </tr>
                                    <tr>
                                        <td>使用结束日期:</td>
                                        <td>
                                            <div class="input-prepend input-group">
			                                <span class="add-on input-group-addon">
			                                    <i class="glyphicon glyphicon-calendar fa fa-calendar"></i>
			                                </span>
                                                <input type="text" value="{$coupon.use_end_time|date='Y-m-d H:i:s',###}"
                                                       class="form-control" id="use_end_time" name="use_end_time">
                                            </div>
                                        </td>
                                        <td class="col-sm-4"></td>
                                    </tr>
                                    </tbody>
                                    <tfoot>
                                    <tr>
                                        <td>
                                            <input type="hidden" name="id" value="{$coupon.id}">
                                        </td>
                                        <td class="col-sm-4"></td>
                                        <td class="text-right"><input class="btn btn-primary" type="button"
                                                                      onclick="coupon_submit()" value="保存"></td>
                                    </tr>
                                    </tfoot>
                                </table>
                            </div>
                        </div>
                    </form><!--表单数据-->
                </div>
            </div>
        </div>
    </section>
</div>

<script>

    function coupon_submit() {
        if ($('input[name=name]').val() == '') {
            layer.msg('优惠券名称不能为空！', {icon: 2, time: 1000});
            return false;
        }
        $('#coupon_form').submit();
    }

    $('input[type="radio"]').click(function () {
        if ($(this).val() == 0) {
            $('.timed').hide();
        } else {
            $('.timed').show();
        }
    })


    $(function () {
        data_pick('send_start_time');
        data_pick('send_end_time');
        data_pick('use_start_time');
        data_pick('use_end_time');
        $('input[type="radio"]:checked').trigger('click');
    })

    function data_pick(id) {
        var myDate = new Date();
        $('#' + id).daterangepicker({
            format: "YYYY-MM-DD HH:mm:ss",
            singleDatePicker: true,
            showDropdowns: true,
            minDate: myDate.getFullYear() + '-' + myDate.getMonth() + '-' + myDate.getDate(),
            maxDate: '2030-01-01',
            timePicker: true, //是否显示小时和分钟
            timePickerIncrement: 1,//time选择递增数
            timePicker12Hour: false, //是否使用12小时制来显示时间
            locale: {
                applyLabel: '确定',
                cancelLabel: '取消',
                fromLabel: '起始时间',
                toLabel: '结束时间',
                customRangeLabel: '自定义',
                daysOfWeek: ['日', '一', '二', '三', '四', '五', '六'],
                monthNames: ['一月', '二月', '三月', '四月', '五月', '六月', '七月', '八月', '九月', '十月', '十一月', '十二月'],
                firstDay: 1
            }
        });
    }
</script>
</body>
</html>